/**********************************************************************/
/*****                                                            *****/
/*****  TITLE:          BJPS Gender Paper (Djupe, McClurg, Sokhey)*****/                        
/*****  UPDATE:         December 2015                             *****/
/*****  DESC:           Code variables from 2008-09 ANES Panel &  *****/
/*****                  estimate models reported in paper         *****/               
/**********************************************************************/

*Additional Notes/Extended Description: 

*The 2008-09 ANES Panel Study is available at: http://www.electionstudies.org/index.htm
*Note: the original file - with all waves - is large. 
*The data were first brought into stata and saved as "anes2008_2009panel.dta" 
*Load "anes2008_2009panel.dta," and then run this do-file 

/*************************************
*syntax begins here:                  */ 
****************************************

*use "location of file anes2008_2009panel.dta here"

*making uppercase variable names lowercase

rename *, lower  
  
*keep variables used for analysis 
 
keep caseid w11zd21 w11zd22 w11zd23 w11zd24 w11zd25 w11zd26 w11zd27 w11zd28 w11zd29 ///
der01 w9age der03a der05 der06 der08w9 w9h1 w9j1 w9zd4_1 w9zd4_2 w9zd4_3 w9zd1 ///
w9zd23_1 w9zd23_2 w9zd23_3 w9zd12_1 w9zd13_1 w9zd14_1 w9zd15_1 w9zd16_1 ///
w9zd12_2 w9zd13_2 w9zd14_2 w9zd15_2 w9zd16_2 ///
w9zd12_3 w9zd13_3 w9zd14_3 w9zd15_3 w9zd16_3 der08w9 wgtl11 w9zd9_1 w9zd9_2 w9zd9_3

******************************************************
******************************************************
*********dependent variables**************************
****************************************************** 
/*(1) components for participation/participatory index */

*this recodes each of the participatory acts -- these appear in the November wave 
*now, 1 is "did the act," and 0 is "did not do the act"  
*also sets to missing "no answer," "not asked," and "not asked/terminated" (-7, -6, -5)

recode  w11zd21 w11zd22 w11zd23 w11zd24 w11zd25 w11zd26 w11zd27 w11zd28 w11zd29 (-7=.) (-6=.) (-5=.) (1=1) (2=0)

*create a base participatory index. 
gen novindex=w11zd21+w11zd22+w11zd23+w11zd24+w11zd25+w11zd26+w11zd27+w11zd28+w11zd29 

*check the reliability of this additive index 
alpha w11zd21 w11zd22 w11zd23 w11zd24 w11zd25 w11zd26 w11zd27 w11zd28 w11zd29 

*note: alpha is .77

************************************************************************************
**additional indices** (not used in paper) ("index3" is used in the paper - below) *
*                                                                                  *
***here's an index that could be considered "confrontational" (3 items)            *
* gen conindex= w11zd21+w11zd29+ w11zd28                                           *
*                                                                                  *
*test the reliability of the additive index:                                       *
*alpha w11zd21 w11zd29  w11zd28                                                    *
*                                                                                  *
*note: alpha is .65                                                                *
*																				   *
*generate an index that could be considered "non-confrontational" (6 items)        *
*gen nonconindex= w11zd22+w11zd23+w11zd24+w11zd25+w11zd26+w11zd27 				   *
*																				   *
*test the reliability															   *
*alpha w11zd22 w11zd23 w11zd24 w11zd25 w11zd26 w11zd27							   *
*																				   *
*note: alpha is .67																   *
************************************************************************************

*this is a version of the additive participatory index to more closely match what's available in other data sets; it counts rallies, 
*giving money, attending meeting, inviting someone to a meeting, and distributing information 

*###########  Note: this is the version used in the paper ################

gen index3= w11zd21+w11zd26+w11zd27+w11zd28+w11zd29

alpha w11zd21 w11zd26 w11zd27 w11zd28 w11zd29 // a=.75


******************************************************
*now, recode the necessary demographics***************
******************************************************
******************************************************

*note: for interest, efficacy, and strength of partisanship, use the wave 9 measures, as that is the same wave as the network items 

recode der01 (1=0) (2=1), gen(female)

rename w9age age 
recode age (-6=.) (-2=.)

recode der03a (0=1) (1=0) (-6=.), gen(nonwhite)

rename der05 educ1to5
recode educ1to5 (-6=.) (-2=.)

rename der06 income
recode income (-6=.) (-2=.)

*strength of partisanship at wave 9 
recode der08w9 (-7=.) (-6=.) (-5=.) (0=3) (1=2) (2=1) (3=0) (4=1) (5=2) (6=3), gen(strpidw9)

*political interest in wave 9  -- recode mising, and flip so higher is more interested 
recode w9h1 (-6=.) (-5=.)
gen interestw9=6-w9h1

*this renames and flips an item on external political efficacy ("how much do govt. officials care about what people like you think?
*(a control, since the DV is a participatory index) 

recode w9j1 (-7=.) (-6=.) (-5=.)
gen expofcarew9=6-w9j1


******************************************************
******************************************************
*political network variables**************************
******************************************************
*note: the panel didn't ask about frequency of discussion in the ego-centric network

*respondents were asked to name up to 8 initials; but additional information was only asked about the first three
*respondents were given a yes/no before naming initials, so people who said "no" can be considered 0s
*again, the network battery appears in wave 9

*the first items just ask about closeness with each named discussant - I'm using them to create valid measures (not worrying about the not asked/invalid codes) 

recode w9zd4_1 (1/5=1), gen(valid1)
recode w9zd4_2 (1/5=1), gen(valid2)
recode w9zd4_3 (1/5=1), gen(valid3)

*this recodes to create an indicator for whether the person actually got asked the discussion questions (not worrying about the not asked/invalid codes)
recode w9zd1 (1=1) (2=1), gen(discvalid)

*create a measure of network size that is valid (as not all people got the discussion questions)

gen netsize=.
replace netsize=0 if discvalid==1
replace netsize=1 if valid1==1
replace netsize=2 if valid2==1
replace netsize=3 if valid3==1
label var netsize "size of Rs network"

*create a network average measure of the level measure of formal education (closest thing in this study to expertise)
*rename the dyads on this measure: 

rename w9zd23_1 formed1
rename w9zd23_2 formed2
rename w9zd23_3 formed3

recode formed1 formed2 formed3 (-7=.) (-6=.) (-5=.) (-1=.)

gen formedavg=.
replace formedavg=0 if netsize==0
replace formedavg=formed1 if netsize==1
replace formedavg=(formed1+formed2)/2 if netsize==2
replace formedavg=(formed1+formed2+formed3)/3 if netsize==3
label var formedavg "average level of formal education in Rs network"

*****************************************************
*****************************************************

*create an average "general" disagreement measure for the network 
**note: this is _not_ based on partisanship, but on "how different the opinions are" from the R

*these flip and rename this difference measure for each discussant 
recode w9zd9_1 w9zd9_2 w9zd9_3 (-6=.) (-5=.) (-1=.)
gen disdisc1=6-w9zd9_1
gen disdisc2=6-w9zd9_2
gen disdisc3=6-w9zd9_3

*now, let's create a network average 
gen avgdis=. 
replace avgdis=0 if netsize==0
replace avgdis=disdisc1 if netsize==1
replace avgdis=(disdisc1+disdisc2)/2 if netsize==2
replace avgdis=(disdisc1+disdisc2+disdisc3)/3 if netsize==3
label var avgdis "average level of opinion difference in Rs network"

*create a network measure of disagreement that follows the logic of Klofstad, Sokhey and McClurg (2012)

*note: seven point party ID is needed for each named discussant 

*note: code this so that 1=strong democrat and 7=strong republican 

gen d1pid7=. 
replace d1pid7=1 if w9zd12_1==1 & w9zd14_1==1 
replace d1pid7=1 if w9zd13_1==2 & w9zd14_1==1 
replace d1pid7=2 if w9zd12_1==1 & w9zd14_1==2 
replace d1pid7=2 if w9zd13_1==2 & w9zd14_1==2
replace d1pid7=3 if w9zd12_1==3 & w9zd16_1==1 
replace d1pid7=3 if w9zd13_1==3 & w9zd16_1==1
replace d1pid7=4 if w9zd12_1==3 & w9zd16_1==3 
replace d1pid7=4 if w9zd13_1==3 & w9zd16_1==3
replace d1pid7=5 if w9zd12_1==3 & w9zd16_1==2 
replace d1pid7=5 if w9zd13_1==3 & w9zd16_1==2
replace d1pid7=6 if w9zd12_1==2 & w9zd15_1==2 
replace d1pid7=6 if w9zd13_1==1 & w9zd15_1==2
replace d1pid7=7 if w9zd12_1==2 & w9zd15_1==1 
replace d1pid7=7 if w9zd13_1==1 & w9zd15_1==1
replace d1pid7=3 if w9zd12_1==4 & w9zd16_1==1
replace d1pid7=5 if w9zd13_1==4 & w9zd16_1==2
replace d1pid7=. if w9zd12_1==4 & w9zd16_1==3
replace d1pid7=. if w9zd13_1==4 & w9zd16_1==3

gen d2pid7=. 
replace d2pid7=1 if w9zd12_2==1 & w9zd14_2==1 
replace d2pid7=1 if w9zd13_2==2 & w9zd14_2==1 
replace d2pid7=2 if w9zd12_2==1 & w9zd14_2==2 
replace d2pid7=2 if w9zd13_2==2 & w9zd14_2==2
replace d2pid7=3 if w9zd12_2==3 & w9zd16_2==1 
replace d2pid7=3 if w9zd13_2==3 & w9zd16_2==1
replace d2pid7=4 if w9zd12_2==3 & w9zd16_2==3 
replace d2pid7=4 if w9zd13_2==3 & w9zd16_2==3
replace d2pid7=5 if w9zd12_2==3 & w9zd16_2==2 
replace d2pid7=5 if w9zd13_2==3 & w9zd16_2==2
replace d2pid7=6 if w9zd12_2==2 & w9zd15_2==2 
replace d2pid7=6 if w9zd13_2==1 & w9zd15_2==2
replace d2pid7=7 if w9zd12_2==2 & w9zd15_2==1 
replace d2pid7=7 if w9zd13_2==1 & w9zd15_2==1
replace d2pid7=3 if w9zd12_2==4 & w9zd16_2==1
replace d2pid7=5 if w9zd13_2==4 & w9zd16_2==2
replace d2pid7=. if w9zd12_2==4 & w9zd16_2==3
replace d2pid7=. if w9zd13_2==4 & w9zd16_2==3

gen d3pid7=. 
replace d3pid7=1 if w9zd12_3==1 & w9zd14_3==1 
replace d3pid7=1 if w9zd13_3==2 & w9zd14_3==1 
replace d3pid7=2 if w9zd12_3==1 & w9zd14_3==2 
replace d3pid7=2 if w9zd13_3==2 & w9zd14_3==2
replace d3pid7=3 if w9zd12_3==3 & w9zd16_3==1 
replace d3pid7=3 if w9zd13_3==3 & w9zd16_3==1
replace d3pid7=4 if w9zd12_3==3 & w9zd16_3==3 
replace d3pid7=4 if w9zd13_3==3 & w9zd16_3==3
replace d3pid7=5 if w9zd12_3==3 & w9zd16_3==2 
replace d3pid7=5 if w9zd13_3==3 & w9zd16_3==2
replace d3pid7=6 if w9zd12_3==2 & w9zd15_3==2 
replace d3pid7=6 if w9zd13_3==1 & w9zd15_3==2
replace d3pid7=7 if w9zd12_3==2 & w9zd15_3==1 
replace d3pid7=7 if w9zd13_3==1 & w9zd15_3==1
replace d3pid7=3 if w9zd12_3==4 & w9zd16_3==1
replace d3pid7=5 if w9zd13_3==4 & w9zd16_3==2
replace d3pid7=. if w9zd12_3==4 & w9zd16_3==3
replace d3pid7=. if w9zd13_3==4 & w9zd16_3==3


*create a summary 

gen sumnetpid=. 
replace sumnetpid=d1pid7 if netsize==1
replace sumnetpid=(d1pid7+d2pid7)/2 if netsize==2
replace sumnetpid=(d1pid7+d2pid7+d3pid7)/3 if netsize==3
label var sumnetpid "average score on 7 point pid in net"

*use main respondent's partisanship at wave 9 (recode to run 1-7 instead of 0-6)
recode der08w9 (0=1) (1=2) (2=3) (3=4) (4=5) (5=6) (6=7), gen(pid1to7)
recode pid1to7 (-6=.)(-7=.)(-5=.)

*susbtract the main respondent's pid from the network average 
gen pidnetdiff=. 
replace pidnetdiff=sumnetpid-pid1to7
replace pidnetdiff=0 if netsize==0

*take the absolute value of this difference
gen absnetdiff=abs(pidnetdiff)

*****************************************************
*****************************************************
****TABLES*******************************************
*****************************************************

*Information for Table 1 in manuscript, third columns of results (i.e., for 08-09 ANES) 

ttest netsize, by(female)
ttest absnetdiff, by(female)
ttest avgdis, by(female)
ttest formedavg, by(female)


*the following produces the information in the footnote (i.e., the overall robustness of the 
*unweighted t-tests to weighted regressions - the results from simple t-tests hold up if 
*differences are estimated as regressions with late panel weights 

regress netsize female [pweight=wgtl11]
regress absnetdiff female [pweight=wgtl11]
regress avgdis female [pweight=wgtl11]
regress formedavg female [pweight=wgtl11]


*****************************************************
*****************************************************
*models appearing in Table 4 of the manuscript and associated graphs (Figure3)     *
*****************************************************
*****************************************************

*note: weight applied is the wave 11, cumulative late panel weight 

***************
***************
***************

*general disagreement specification (Table 4, left column), with weights (per ANES documentation) 
poisson index3 i.female##c.avgdis i.female##c.formedavg i.female##c.netsize educ1to5 income strpidw9 age interestw9 expofcarew9 nonwhite if netsize>0 [pweight=wgtl11]

*this produces the estimates for the graph in panel A of Figure 3: 
margins, dydx(avgdis formedavg netsize) at(female=(0)) l(90)
margins, dydx(avgdis formedavg netsize) at(female=(1)) l(90)

*this produces the graph in panel C of Figure 3: 
margins, dydx(female) at(formedavg=(0(1)14)) atmeans level(90)
marginsplot, level(90) yline(0, lc(black)) ytitle("Marginal Effect of Gender (Female) on Participation") graphregion(color(white)) ///
	xtitle("Level of Network Education") recastci(rspike) ciopt(lp(dash) lc(gs10)) plotop(mc(black) lc(black)) title("Gender, Network Education, and Participation" "General Disagreeement Specification", c(black))

*general disagreement specification, without weights (for SI)
poisson index3 i.female##c.avgdis i.female##c.formedavg i.female##c.netsize educ1to5 income strpidw9 age interestw9 expofcarew9 nonwhite if netsize>0 

****************
****************
****************

*partisan disagreement specification (Table 4, right column), with weights (per ANES documentation) 
poisson index3 i.female##c.absnetdiff i.female##c.formedavg i.female##c.netsize educ1to5 income strpidw9 age interestw9 expofcarew9 nonwhite if netsize>0 [pweight=wgtl11]

*these are the estimates for the graph in panel B of Figure 3: 
margins, dydx(absnetdiff formedavg netsize) at(female=(0)) l(90)
margins, dydx(absnetdiff formedavg netsize) at(female=(1)) l(90)


*this forms the graph in panel D of Figure 3: 
margins, dydx(female) at(absnetdiff=(0(.5)6)) atmeans level(90)
marginsplot, level(90) yline(0, lc(black)) ytitle("Marginal Effect of Gender (Female) on Participation") graphregion(color(white)) ///
	xtitle("Network Partisan Disagreement") recastci(rspike) ciopt(lp(dash) lc(gs10)) plotop(mc(black) lc(black)) title("Gender, Partisan Disagreement, and Participation" "Partisan Disagreeement Specification", c(black))


*partisan disagreement specification, without weights 
poisson index3 i.female##c.absnetdiff i.female##c.formedavg i.female##c.netsize educ1to5 income strpidw9 age interestw9 expofcarew9 nonwhite if netsize>0 


**********************************************************
**********************************************************
*SI materials                                            *
**********************************************************

*summary statistics for variables in Table 4

sum index3 female absnetdiff avgdis formedavg netsize educ1to5 income strpidw9 age interestw9 expofcarew9 nonwhite
